package utils;

import org.testng.annotations.Test;

import java.util.Objects;

public class Student implements Comparable<Student>{
    private String name;
    private int score;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    public Student(String name, int score) {
        this.name = name;
        this.score = score;
    }

    @Override
    public int compareTo(Student o) {
        return o.score - this.score != 0 ? o.score - this.score :this.name.compareTo(o.name);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return score == student.score &&
                Objects.equals(name, student.name);
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", score=" + score +
                '}';
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, score);
    }

    @Test
    public static void testing() {
        Student stu1 = new Student("jack", 96);
        Student stu2 = new Student("tom", 95);
        Student stu3 = new Student("jim", 96);
        Student stu4 = new Student("jack", 96);
        Student stu5 = new Student("jack", 96);
        System.out.println(stu1.compareTo(stu2));
        System.out.println(stu3.compareTo(stu4));

    }
}
